<!DOCTYPE HTML>
<html lang="en" >
    <!-- Start book NoSQL简介 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>创建集群 | NoSQL简介</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../part4/7_4.html" />
    
    
    <link rel="prev" href="../part4/7_2.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="7.3"
        data-chapter-title="创建集群"
        data-filepath="part4/7_3.md"
        data-basepath=".."
        data-revision="Thu Nov 02 2017 21:26:40 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="part1/1.html">
            
                
                    <a href="../part1/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="part1/2.html">
            
                
                    <a href="../part1/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3" data-path="part1/3.html">
            
                
                    <a href="../part1/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        服务器与客户端
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4" data-path="part2/4.html">
            
                
                    <a href="../part2/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        数据操作
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="part2/4_1.html">
            
                
                    <a href="../part2/4_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        string
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="part2/4_2.html">
            
                
                    <a href="../part2/4_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        键命令
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="part2/4_3.html">
            
                
                    <a href="../part2/4_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        hash
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="part2/4_4.html">
            
                
                    <a href="../part2/4_4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        list
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="part2/4_5.html">
            
                
                    <a href="../part2/4_5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        set
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="part2/4_6.html">
            
                
                    <a href="../part2/4_6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        zset
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="part3/5.html">
            
                
                    <a href="../part3/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        与python交互
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="part3/5_1.html">
            
                
                    <a href="../part3/5_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="part3/5_2.html">
            
                
                    <a href="../part3/5_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        string-增加
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="part3/5_3.html">
            
                
                    <a href="../part3/5_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        string-获取
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="part3/5_4.html">
            
                
                    <a href="../part3/5_4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        string-修改
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="part3/5_5.html">
            
                
                    <a href="../part3/5_5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        string-删除
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="part3/5_6.html">
            
                
                    <a href="../part3/5_6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        获取键
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="part4/6.html">
            
                
                    <a href="../part4/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        搭建主从
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7" data-path="part4/7.html">
            
                
                    <a href="../part4/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        搭建集群
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="part4/7_1.html">
            
                
                    <a href="../part4/7_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        配置机器1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="part4/7_2.html">
            
                
                    <a href="../part4/7_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        配置机器2
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="7.3" data-path="part4/7_3.html">
            
                
                    <a href="../part4/7_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        创建集群
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="part4/7_4.html">
            
                
                    <a href="../part4/7_4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        Python交互
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="8.html">
            
                
                    <a href="../8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >NoSQL简介</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x521B;&#x5EFA;&#x96C6;&#x7FA4;">&#x521B;&#x5EFA;&#x96C6;&#x7FA4;</h1>
<ul>
<li>redis&#x7684;&#x5B89;&#x88C5;&#x5305;&#x4E2D;&#x5305;&#x542B;&#x4E86;redis-trib.rb&#xFF0C;&#x7528;&#x4E8E;&#x521B;&#x5EFA;&#x96C6;&#x7FA4;</li>
<li>&#x63A5;&#x4E0B;&#x6765;&#x7684;&#x64CD;&#x4F5C;&#x5728;192.168.12.107&#x673A;&#x5668;&#x4E0A;&#x8FDB;&#x884C;</li>
<li>&#x5C06;&#x547D;&#x4EE4;&#x590D;&#x5236;&#xFF0C;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x5728;&#x4EFB;&#x4F55;&#x76EE;&#x5F55;&#x4E0B;&#x8C03;&#x7528;&#x6B64;&#x547D;&#x4EE4;</li>
</ul>
<pre><code>sudo cp /usr/share/doc/redis-tools/examples/redis-trib.rb /usr/local/bin/
</code></pre><ul>
<li>&#x5B89;&#x88C5;ruby&#x73AF;&#x5883;&#xFF0C;&#x56E0;&#x4E3A;redis-trib.rb&#x662F;&#x7528;ruby&#x5F00;&#x53D1;&#x7684;</li>
</ul>
<pre><code>sudo apt-get install ruby
</code></pre><ul>
<li>&#x5728;&#x63D0;&#x793A;&#x4FE1;&#x606F;&#x5904;&#x8F93;&#x5165;y&#xFF0C;&#x7136;&#x540E;&#x56DE;&#x8F66;&#x7EE7;&#x7EED;&#x5B89;&#x88C5;</li>
</ul>
<p><img src="images/p7_3.png" alt="&#x96C6;&#x7FA4;"></p>
<ul>
<li>&#x8FD0;&#x884C;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#x521B;&#x5EFA;&#x96C6;&#x7FA4;</li>
</ul>
<pre><code>redis-trib.rb create --replicas 1 192.168.12.107:7000 192.168.12.107:7001  192.168.12.107:7002 192.168.12.84:7003  192.168.12.84:7004  192.168.12.84:7005
</code></pre><ul>
<li>&#x63D0;&#x793A;&#x5982;&#x4E0B;&#x4E3B;&#x4ECE;&#x4FE1;&#x606F;&#xFF0C;&#x8F93;&#x5165;yes&#x540E;&#x56DE;&#x8F66;</li>
</ul>
<p><img src="images/p7_4.png" alt="&#x96C6;&#x7FA4;"></p>
<ul>
<li>&#x63D0;&#x793A;&#x5B8C;&#x6210;&#xFF0C;&#x96C6;&#x7FA4;&#x642D;&#x5EFA;&#x6210;&#x529F;</li>
</ul>
<h4 id="&#x6570;&#x636E;&#x9A8C;&#x8BC1;">&#x6570;&#x636E;&#x9A8C;&#x8BC1;</h4>
<ul>
<li>&#x6839;&#x636E;&#x4E0A;&#x56FE;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#xFF0C;&#x5F53;&#x524D;&#x642D;&#x5EFA;&#x7684;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x4E3A;7000&#x3001;7001&#x3001;7003&#xFF0C;&#x5BF9;&#x5E94;&#x7684;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x662F;7004&#x3001;7005&#x3001;7002</li>
<li>&#x5728;192.168.12.107&#x673A;&#x5668;&#x4E0A;&#x8FDE;&#x63A5;7002&#xFF0C;&#x52A0;&#x53C2;&#x6570;-c&#x8868;&#x793A;&#x8FDE;&#x63A5;&#x5230;&#x96C6;&#x7FA4;</li>
</ul>
<pre><code>redis-cli -h 192.168.12.107 -c -p 7002
</code></pre><ul>
<li>&#x5199;&#x5165;&#x6570;&#x636E;</li>
</ul>
<pre><code>set hello world
</code></pre><ul>
<li>&#x81EA;&#x52A8;&#x8DF3;&#x5230;&#x4E86;7000&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x5E76;&#x5199;&#x5165;&#x6570;&#x636E;&#x6210;&#x529F;</li>
</ul>
<p><img src="images/p7_5.png" alt="&#x96C6;&#x7FA4;"></p>
<ul>
<li>7000&#x5BF9;&#x5E94;&#x7684;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x4E3A;7004&#xFF0C;&#x6240;&#x4EE5;&#x5728;192.168.12.84&#x670D;&#x52A1;&#x5668;&#x8FDE;&#x63A5;7004&#xFF0C;&#x67E5;&#x770B;&#x6570;&#x636E;&#x5982;&#x4E0B;&#x56FE;</li>
</ul>
<p><img src="images/p7_6.png" alt="&#x96C6;&#x7FA4;"></p>
<ul>
<li>&#x5728;192.168.12.84&#x670D;&#x52A1;&#x5668;&#x8FDE;&#x63A5;7005&#x662F;&#x6CA1;&#x6709;&#x6570;&#x636E;&#x7684;</li>
</ul>
<p><img src="images/p7_7.png" alt="&#x96C6;&#x7FA4;"></p>
<h4 id="&#x5728;&#x54EA;&#x4E2A;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x5199;&#x6570;&#x636E;&#xFF1A;crc16">&#x5728;&#x54EA;&#x4E2A;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x5199;&#x6570;&#x636E;&#xFF1A;CRC16</h4>
<ul>
<li>redis cluster&#x5728;&#x8BBE;&#x8BA1;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5C31;&#x8003;&#x8651;&#x5230;&#x4E86;&#x53BB;&#x4E2D;&#x5FC3;&#x5316;&#xFF0C;&#x53BB;&#x4E2D;&#x95F4;&#x4EF6;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x96C6;&#x7FA4;&#x4E2D;&#x7684;&#x6BCF;&#x4E2A;&#x8282;&#x70B9;&#x90FD;&#x662F;&#x5E73;&#x7B49;&#x7684;&#x5173;&#x7CFB;&#xFF0C;&#x90FD;&#x662F;&#x5BF9;&#x7B49;&#x7684;&#xFF0C;&#x6BCF;&#x4E2A;&#x8282;&#x70B9;&#x90FD;&#x4FDD;&#x5B58;&#x5404;&#x81EA;&#x7684;&#x6570;&#x636E;&#x548C;&#x6574;&#x4E2A;&#x96C6;&#x7FA4;&#x7684;&#x72B6;&#x6001;&#x3002;&#x6BCF;&#x4E2A;&#x8282;&#x70B9;&#x90FD;&#x548C;&#x5176;&#x4ED6;&#x6240;&#x6709;&#x8282;&#x70B9;&#x8FDE;&#x63A5;&#xFF0C;&#x800C;&#x4E14;&#x8FD9;&#x4E9B;&#x8FDE;&#x63A5;&#x4FDD;&#x6301;&#x6D3B;&#x8DC3;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x4FDD;&#x8BC1;&#x4E86;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x8FDE;&#x63A5;&#x96C6;&#x7FA4;&#x4E2D;&#x7684;&#x4EFB;&#x610F;&#x4E00;&#x4E2A;&#x8282;&#x70B9;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x5230;&#x5176;&#x4ED6;&#x8282;&#x70B9;&#x7684;&#x6570;&#x636E;</li>
<li>Redis&#x96C6;&#x7FA4;&#x6CA1;&#x6709;&#x5E76;&#x4F7F;&#x7528;&#x4F20;&#x7EDF;&#x7684;&#x4E00;&#x81F4;&#x6027;&#x54C8;&#x5E0C;&#x6765;&#x5206;&#x914D;&#x6570;&#x636E;&#xFF0C;&#x800C;&#x662F;&#x91C7;&#x7528;&#x53E6;&#x5916;&#x4E00;&#x79CD;&#x53EB;&#x505A;&#x54C8;&#x5E0C;&#x69FD; (hash slot)&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x5206;&#x914D;&#x7684;&#x3002;redis cluster &#x9ED8;&#x8BA4;&#x5206;&#x914D;&#x4E86; 16384 &#x4E2A;slot&#xFF0C;&#x5F53;&#x6211;&#x4EEC;set&#x4E00;&#x4E2A;key &#x65F6;&#xFF0C;&#x4F1A;&#x7528;CRC16&#x7B97;&#x6CD5;&#x6765;&#x53D6;&#x6A21;&#x5F97;&#x5230;&#x6240;&#x5C5E;&#x7684;slot&#xFF0C;&#x7136;&#x540E;&#x5C06;&#x8FD9;&#x4E2A;key &#x5206;&#x5230;&#x54C8;&#x5E0C;&#x69FD;&#x533A;&#x95F4;&#x7684;&#x8282;&#x70B9;&#x4E0A;&#xFF0C;&#x5177;&#x4F53;&#x7B97;&#x6CD5;&#x5C31;&#x662F;&#xFF1A;CRC16(key) % 16384&#x3002;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x5728;&#x6D4B;&#x8BD5;&#x7684;&#x65F6;&#x5019;&#x770B;&#x5230;set &#x548C; get &#x7684;&#x65F6;&#x5019;&#xFF0C;&#x76F4;&#x63A5;&#x8DF3;&#x8F6C;&#x5230;&#x4E86;7000&#x7AEF;&#x53E3;&#x7684;&#x8282;&#x70B9;</li>
<li>Redis &#x96C6;&#x7FA4;&#x4F1A;&#x628A;&#x6570;&#x636E;&#x5B58;&#x5728;&#x4E00;&#x4E2A; master &#x8282;&#x70B9;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x8FD9;&#x4E2A; master &#x548C;&#x5176;&#x5BF9;&#x5E94;&#x7684;salve &#x4E4B;&#x95F4;&#x8FDB;&#x884C;&#x6570;&#x636E;&#x540C;&#x6B65;&#x3002;&#x5F53;&#x8BFB;&#x53D6;&#x6570;&#x636E;&#x65F6;&#xFF0C;&#x4E5F;&#x6839;&#x636E;&#x4E00;&#x81F4;&#x6027;&#x54C8;&#x5E0C;&#x7B97;&#x6CD5;&#x5230;&#x5BF9;&#x5E94;&#x7684; master &#x8282;&#x70B9;&#x83B7;&#x53D6;&#x6570;&#x636E;&#x3002;&#x53EA;&#x6709;&#x5F53;&#x4E00;&#x4E2A;master &#x6302;&#x6389;&#x4E4B;&#x540E;&#xFF0C;&#x624D;&#x4F1A;&#x542F;&#x52A8;&#x4E00;&#x4E2A;&#x5BF9;&#x5E94;&#x7684; salve &#x8282;&#x70B9;&#xFF0C;&#x5145;&#x5F53; master</li>
<li>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF1A;&#x5FC5;&#x987B;&#x8981;3&#x4E2A;&#x6216;&#x4EE5;&#x4E0A;&#x7684;&#x4E3B;&#x8282;&#x70B9;&#xFF0C;&#x5426;&#x5219;&#x5728;&#x521B;&#x5EFA;&#x96C6;&#x7FA4;&#x65F6;&#x4F1A;&#x5931;&#x8D25;&#xFF0C;&#x5E76;&#x4E14;&#x5F53;&#x5B58;&#x6D3B;&#x7684;&#x4E3B;&#x8282;&#x70B9;&#x6570;&#x5C0F;&#x4E8E;&#x603B;&#x8282;&#x70B9;&#x6570;&#x7684;&#x4E00;&#x534A;&#x65F6;&#xFF0C;&#x6574;&#x4E2A;&#x96C6;&#x7FA4;&#x5C31;&#x65E0;&#x6CD5;&#x63D0;&#x4F9B;&#x670D;&#x52A1;&#x4E86;</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../part4/7_2.html" class="navigation navigation-prev " aria-label="Previous page: 配置机器2"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../part4/7_4.html" class="navigation navigation-next " aria-label="Next page: Python交互"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book NoSQL简介 -->
</html>
